var t = require("../../../../mybehaviors/location/location"), a = getApp();

Component({
    behaviors: [ t ],
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        U_homedata: {
            type: null
        },
        index: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        countData: {},
        region_name: ""
    },
    lifetimes: {
        attached: function() {},
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        var t = this;
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this._getLocation(function(a, e) {
            t.setData({
                region_name: a.address_component[t.data.datas.city_type]
            }), t.getData(), console.log(a), t.recordLocation({
                point: a.location,
                addressComponent: a.address_component
            });
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        getData: function() {
            var t = this, e = a.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-count");
            a._postNetWork({
                url: e,
                data: {
                    city_type: this.data.datas.city_type,
                    region_name: this.data.region_name
                },
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var o = {
                            all_stores_count: t.transform(parseInt(e.data.sotreCount + t.data.datas.all_stores_count)),
                            all_fans_count: t.transform(parseInt(e.data.memberCount + t.data.datas.all_fans_count)),
                            local_stores_count: t.transform(parseInt(e.data.sotreCityCount + t.data.datas.local_stores_count)),
                            local_fans_count: t.transform(parseInt(e.data.memberCityCount + t.data.datas.local_fans_count))
                        };
                        t.setData({
                            countData: o
                        }), console.log(t.data.countData);
                    } else {
                        t.setData({
                            countData: {
                                all_stores_count: 0,
                                all_fans_count: 0,
                                local_stores_count: 0,
                                local_fans_count: 0
                            }
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        recordLocation: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}, e = a.getNetAddresss("member.member.save-member-location");
            console.log(t);
            var o = a.BMapTransqqMap(parseFloat(t.point.lng), parseFloat(t.point.lat));
            a._postNetWork({
                url: e,
                data: {
                    province_name: t.addressComponent.province,
                    city_name: t.addressComponent.city,
                    district_name: t.addressComponent.district,
                    longitude: o.lng,
                    latitude: o.lat
                },
                success: function(t) {},
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        transform: function(t) {
            for (var a = [ "", "", "" ], e = 1e3, o = 3, n = 1; t / e >= 1; ) e *= 10, o += 1;
            if (o <= 4) a[1] = "千", a[0] = parseFloat(t / 1e3) + ""; else if (o <= 8) {
                var s = parseInt(o - 4) / 3 > 1 ? "千万" : "万";
                n = "万" === s ? 1e4 : 1e7, a[1] = s, a[0] = t / n + "";
            } else if (o <= 16) {
                var r = (o - 8) / 3 > 1 ? "千亿" : "亿";
                r = (o - 8) / 4 > 1 ? "万亿" : r, n = 1, "亿" === (r = (o - 8) / 7 > 1 ? "千万亿" : r) ? n = 1e8 : "千亿" === r ? n = 1e11 : "万亿" === r ? n = 1e12 : "千万亿" === r && (n = 1e15), 
                a[1] = r, a[0] = parseFloat(t / n) + "";
            }
            return t < 1e3 && (a[1] = "", a[0] = t + ""), a.join("");
        }
    }
});